package com.leecode.xiehf.page_14;

import java.util.List;
import java.util.stream.Collectors;


public class Solution_0690 {

    public int getImportance(List<Employee> employees, int id) {
        List<Employee> collect = employees.stream().filter(employee -> employee.id == id).collect(Collectors.toList());
        if (collect.size() > 0) {
            employees.removeAll(collect);
            return loop(employees, collect);
        }
        return 0;
    }

    int loop(List<Employee> all, List<Employee> list) {
        if (list == null || list.size() == 0) {
            return 0;
        }
        int res = 0;
        for (Employee emp : list) {
            int importance = emp.importance;
            res += importance;
            res += loop(all, all.stream().filter(e -> emp.subordinates.contains(e.id)).collect(Collectors.toList()));
        }
        return res;
    }
    public class Employee {
        public int id;
        public int importance;
        public List<Integer> subordinates;
    }
}
